import os
import sys
import threading
from libs.tornado import web, log, ioloop

from libs import parseOption
log.enable_pretty_logging()

class Application(web.Application):
    def __init__(self, debug_mode):

        index_handlers = []

        handlers = index_handlers

        settings = dict(
            web_title=u"zeroPastry",
            template_path=os.path.join(os.path.dirname(__file__), "static/templates"),
            static_path=os.path.join(os.path.dirname(__file__), "static"),
            debug=debug_mode,
        )
        super(Application, self).__init__(handlers, **settings)


# 調試模式

def start(port):
    app = Application(debug_mode=True)
    app.listen(port, address="127.0.0.1")
    ioloop.IOLoop.current().start()


if __name__ == '__main__':
    port = parseOption.get_port()
    print("zeroPastry Running On Port {}".format(port))
    start(port)
